package cn.lili.modules.share.entity.dto;

import cn.hutool.core.util.StrUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.share.entity.docs.AppUser;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("appUserDTO类")
public class AppUserDTO extends PageVO {

    @ApiModelProperty("是否已完成购物: 1,已购买 2,未完成")
    private Integer type;

    @ApiModelProperty("上级openid")
    private String superior;

    @ApiModelProperty("用户openid")
    private String openid;


    public LambdaQueryWrapper<AppUser> toQueryWrapper() {
        LambdaQueryWrapper<AppUser> query = new LambdaQueryWrapper<>();
        query.eq(StrUtil.isNotEmpty(superior), AppUser::getSuperior, superior);
        query.eq(StrUtil.isNotEmpty(openid), AppUser::getOpenid, openid);
        if (type != null && type == 1) {
            query.eq(true, AppUser::getIs_true, type);
        } else if (type != null && type == 2) {
            query.eq(true, AppUser::getIs_true, 0);
        }
        query.orderByDesc(AppUser::getId);
        return query;
    }


    /**
     * 查找排名列表
     * @return
     */
    public LambdaQueryWrapper toQueryRankingWrapper(){
        LambdaQueryWrapper<AppUser> query = new LambdaQueryWrapper<>();
        query.select(AppUser::getHead, AppUser::getAccount, AppUser::getOpenid, AppUser::getTuiguang);
        query.eq(StrUtil.isNotEmpty(superior), AppUser::getSuperior, superior);
        query.eq(StrUtil.isNotEmpty(openid), AppUser::getOpenid, openid);
        query.gt(true, AppUser::getTuiguang, 0);
        query.orderByDesc(AppUser::getTuiguang).orderByAsc(AppUser::getId);
        return query;
    }



}
